﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Data;
public partial class Ajax_3d_zs : System.Web.UI.Page
{
    public List<Model.LotteryAnnouncement> GetPageListSQl(int PageIndex, int PageSize, string sql, out int totalCount)
    {

        string primaryKey = "openTime";
        totalCount = new DataAccess().GetCount<Model.LotteryAnnouncement>(primaryKey, sql);
        return new DataAccess().GetPage_List<Model.LotteryAnnouncement>(PageIndex, PageSize, primaryKey, primaryKey + " desc", sql);

    }
    protected void Page_Load(object sender, EventArgs e)
    {
        HttpContext c = HttpContext.Current;
        string shouqiujiou = "";
        string shouqiudx = "";
        string shouqiusanlu = "";
        string qiusiqu = "";


        int lotteryType = ReadRequest.RequestInt("type");
        int count = ReadRequest.RequestInt("counts");
        int qsType = ReadRequest.RequestInt("qsType");//区分球1，球2，球3
        int totalCount = 0;

        string sqlwhere = "LotteryType =" + lotteryType;


        List<Model.LotteryAnnouncement> modellist = GetPageListSQl(0, count, sqlwhere, out totalCount);

        if (count > 200)
        {
            modellist = modellist.FindAll(d => d.openTime.Year == count);

        }
        if (modellist != null)
        {

            for (int i = modellist.Count - 1; i >= 0; i--)
            {
                #region
                string[] redBall = modellist[i].LotteryNo.Split(',');
                int ball = 0;
                if (qsType == 1)//球1
                {
                    ball = int.Parse(redBall[0]);
                }
                else if (qsType == 2)//球2
                {
                    ball = int.Parse(redBall[1]);
                }
                else if (qsType == 3)//球3
                {
                    ball = int.Parse(redBall[2]);
                }
                else if (qsType == 4)//和值
                {
                    ball = int.Parse(redBall[0]) + int.Parse(redBall[1]) + int.Parse(redBall[2]);

                    if (ball > 0 && ball <= 6)
                    {
                        qiusiqu += "1" + ",";//四区1
                    }
                    else if (ball > 6 && ball <= 13)
                    {
                        qiusiqu += "2" + ",";//四区2
                    }
                    else if (ball > 13 && ball <= 20)
                    {
                        qiusiqu += "3" + ",";//四区3
                    }
                    else if (ball > 20 && ball <= 27)
                    {
                        qiusiqu += "4" + ",";//四区4
                    }

                }

                //球1
                if (ball % 2 == 0)
                {
                    shouqiujiou += "1" + ","; //双
                }
                else
                {
                    shouqiujiou += "0" + ","; //单
                }
                if (qsType == 4)
                {
                    if (ball >= 0 && ball <= 13)
                    {
                        shouqiudx += "1" + ","; //小
                    }
                    else if (ball > 13 && ball <= 27)
                    {
                        shouqiudx += "0" + ",";  //大 
                    }
                }
                else
                {
                    if (ball >= 0 && ball <= 4)
                    {
                        shouqiudx += "1" + ","; //小
                    }
                    else if (ball > 4 && ball <= 9)
                    {
                        shouqiudx += "0" + ",";  //大 
                    }
                }


                if (ball % 3 == 0)
                {
                    shouqiusanlu += "0" + ","; //三路0
                }
                else if (ball % 3 == 1)
                {
                    shouqiusanlu += "1" + ","; //三路1
                }
                else if (ball % 3 == 2)
                {
                    shouqiusanlu += "2" + ","; //三路2
                }
                #endregion
            }
            shouqiujiou = shouqiujiou.TrimEnd(',');
            shouqiudx = shouqiudx.TrimEnd(',');
            shouqiusanlu = shouqiusanlu.TrimEnd(',');
            qiusiqu = qiusiqu.TrimEnd(',');

        }

        if (qsType == 4)
        {
            Response.Write(shouqiujiou + "*" + shouqiudx + "*" + shouqiusanlu + "*" + qiusiqu);
        }
        else
        {
            Response.Write(shouqiujiou + "*" + shouqiudx + "*" + shouqiusanlu);
        }
        Response.End();
    }
}